﻿@using Dignite.FileExplorer.Files;
@using Volo.Abp.AspNetCore.Components
@inherits AbpComponentBase
<Validation Validator="@(Validator ?? ValidationRule.None)" AsyncValidator="@AsyncValidator">
    <FileEdit @ref="FileEditRef" Changed="@OnFileChangedAsync" Multiple="@Multiple" MaxFileSize="@MaxFileSize" Filter="@Configuration?.AllowedFileTypeNames?.JoinAsString(",")" />
</Validation>
@if (FileDescriptorsContent != null)
{
    @FileDescriptorsContent(FileDescriptors)
}
else
{
    if (FileDescriptors != null && FileDescriptors.Any())
    {
        <Table>
            <TableHeader>
                <TableRow>
                    <TableHeaderCell>@L["FileName"]</TableHeaderCell>
                    <TableHeaderCell>@L["FileSize"]</TableHeaderCell>
                    <TableHeaderCell></TableHeaderCell>
                </TableRow>
            </TableHeader>
            <TableBody>
                @foreach (var item in FileDescriptors)
                {
                    <TableRow>
                        <TableRowCell>@item.Name</TableRowCell>
                        <TableRowCell>@FileSizeFormatter.FormatSize(item.Size)</TableRowCell>
                        <TableRowCell>
                            <Button Color="Color.Primary" Clicked="@(()=>RemoveFileAsync(item))"><Icon Name="@IconName.Delete"></Icon></Button>
                        </TableRowCell>
                    </TableRow>
                }          
            </TableBody>
        </Table>
    }
}
@if (FilesContent != null)
{
    @FilesContent(Files)
}
else
{
    @if (Files != null && Files.Any())
    {
        <Table>
            <TableHeader>
                <TableRow>
                    <TableHeaderCell>@L["FileName"]</TableHeaderCell>
                    <TableHeaderCell>@L["FileSize"]</TableHeaderCell>
                    <TableHeaderCell></TableHeaderCell>
                </TableRow>
            </TableHeader>
            <TableBody>
                @foreach (var item in Files)
                {
                    <TableRow>
                        <TableRowCell>
                            @item.File.Name
                            @if (item.Status == FileUploadStatus.Fail)
                            {
                                <Paragraph TextColor="TextColor.Danger">
                                    @item.ErrorMessage
                                </Paragraph>
                            }
                        </TableRowCell>
                        <TableRowCell>@FileSizeFormatter.FormatSize(item.File.Size)</TableRowCell>
                        <TableRowCell>
                            @if (item.Status == FileUploadStatus.Fail)
                            {
                                <Icon Name="IconName.TimesCircle" TextColor="TextColor.Danger"></Icon>
                            }
                            else
                            {
                                <Button Color="Color.Primary" Clicked="@(()=>RemoveFileAsync(item))">
                                    <Icon Name="@IconName.Delete"></Icon>
                                </Button>
                            }
                        </TableRowCell>
                    </TableRow>
                }
            </TableBody>
        </Table>
    }
}
